<?php

namespace App\Admin\Controllers;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use App\Models\Circle;
use App\Models\Product;
use Encore\Admin\Controllers\AdminController;

class CirclesController extends AdminController
{
    protected $title = '发圈列表';

    protected function grid()
    {
        $grid = new Grid(new Circle());
        $grid->model()->orderBy('id');

        $grid->column('id', 'ID');
      
        $grid->column('title', '标题');
        $grid->column('product_id', '商品')->display(function () {
            return isset($this->product) ? "{$this->product->id}: {$this->product->title}" : '';
        });
        $grid->column('is_sale', '上架')->bool();
        $grid->column('is_top', '置顶')->bool();
        $grid->disableRowSelector();
        $grid->disableColumnSelector();
        $grid->disableExport();
        $this->gridFilter($grid);
        $this->gridActions($grid);

        return $grid;
    }

	protected function gridActions(Grid $grid)
	{
		$grid->actions(function (Grid\Displayers\Actions $actions) {
			$actions->disableView();
			//$actions->disableDelete();
		});
	}

    protected function gridFilter(Grid $grid)
    {
        $grid->filter(function (Grid\Filter $filter) {
            $filter->expand();

            $filter->column(1/2, function (Grid\Filter $filter) {
                $filter->disableIdFilter();
                $filter->like('title', '标题查询');
                

            });

           
        });
    }
     protected function form()
    {
        $form = new Form(new Circle());

        $form->textarea('title','标题')->rules('required');
        $form->file('video', '视频')->removable();
        $form->multipleImage('images', '图片')->removable();
        $form->select('product_id','商品')->options(Product::query()->where('is_sale',true)->where('is_group',true)->get()->pluck('title_long', 'id'));
        $form->radio('is_sale', '上架')->options(config('site.bool'))->default(false);
        $form->radio('is_top', '置顶')->options(config('site.bool'))->default(false);

        return $form;
    }
}
